from appium import webdriver

from base.base_page import BasePage
from page.main import Main


class App(BasePage):
    def start(self):
        if self._driver is None:
            desired_caps = {
                "platformName": "Android",
                "platformVersion": "6.0",
                "deviceName": "192.168.57.101:5555",
                "appPackage": "com.xueqiu.android",
                "appActivity": ".common.MainActivity",
                "resetKeyBoard": True,
                "unicodeKeyboard": True,
                "noReset": True,
                "automationName": "Uiautomator2"
                # 'skipServerInstallation': True,
                # 'skipDeviceInitialization': True
            }

            self._driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
        else:
            self._driver.launch_app()

        self._driver.implicitly_wait(10)

        return self

    def restart(self):
        pass

    def stop(self):
        if self._driver is not None:
            self._driver.quit()
            self._driver = None

    def main(self):
        return Main(self._driver)
